/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cip.esymons.tesoreria.converters;

import org.cip.esymons.general.util.ControladorAbstracto;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import org.cip.esymons.tesoreria.beans.TipoDocumentoTesoreriaController;
import org.cip.esymons.tramite.be.TipoDocumento;

/**
 *
 * @author Ingrid Capuñay
 */
public class TipoDocumentoTesoreriaConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value == null) {
            return null;
        }
        try {
            Long id = new Long(value);
            TipoDocumentoTesoreriaController controller = (TipoDocumentoTesoreriaController) ControladorAbstracto.getBean("tipoDocumentoTesoreriaController");
            return controller.buscarPorCodigo(id);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value == null) {
            return null;
        }
        if (value instanceof TipoDocumento) {
            TipoDocumento o = (TipoDocumento) value;
            return "" + o.getTdoCodigo();
        } else {
            return null;
        }
    }
}
